package com.smedi.ismedi.notification.core.port.adapter.restful;

import com.smedi.ismedi.notification.api.dto.request.SendMailRequest;
import com.smedi.ismedi.notification.api.feign.RemoteMailNotificationFeignApi;
import com.smedi.ismedi.notification.core.application.command.SendMailCommand;
import com.smedi.ismedi.notification.core.application.service.MailNotificationApplicationService;
import com.smedi.ismedi.web.starter.common.ResponseData;
import com.smedi.ismedi.web.starter.util.DozerUtil;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @className: MailNotificationController
 * @Description: TODO
 * @version: v1.0.0
 * @author: wzx
 * @date: 2022/11/23 14:54
 */

@Slf4j
@RestController
@AllArgsConstructor
public class MailNotificationController implements RemoteMailNotificationFeignApi {

    private final DozerUtil dozerUtil;

    private final MailNotificationApplicationService mailNotificationApplicationService;

    @Override
    public ResponseData<Boolean> postSendShortMessage(SendMailRequest sendMailRequest) {
        SendMailCommand sendMailCommand = dozerUtil.convertor(sendMailRequest, SendMailCommand.class);
        mailNotificationApplicationService.sendMail(sendMailCommand);
        return new ResponseData<Boolean>().success(true);
    }

    @Override
    public ResponseData<Boolean> postSendShortMessage(List<SendMailRequest> sendMailRequests) {
        for (SendMailRequest sendMailRequest : sendMailRequests) {
            this.postSendShortMessage(sendMailRequest);
        }
        return new ResponseData<Boolean>().success(true);
    }
}